<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex align-stretch benben-position-layout flex recommendCommodityList_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex align-center justify-between flex-sub recommendCommodityList_fd0_0'>
					<view class='flex align-center' @tap="handleJumpDiy" data-type="back" data-url="1">
						<text class='fu-iconfont2  recommendCommodityList_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<view class='flex align-center flex-sub recommendCommodityList_fd0_0_c1'>
						<image class='recommendCommodityList_fd0_0_c1_c0' mode="aspectFit" :src='STATIC_URL+"145.png"'>
						</image>
						<benben-input class='flex-sub recommendCommodityList_fd0_0_c1_c1' type="text"
							:placeholder="`请输入关键字搜索`" confirm-type="done" :maxlength="-1"
							placeholder-style="color:rgba(153, 153, 153, 1);font-size:28rpx" @confirm="searchFunc()"
							v-model="keyword" />
						<image v-if="keyword" class='recommendCommodityList_fd0_0_c1_c2' mode="aspectFit" :src='STATIC_URL+"149.png"'
							@tap.stop="clearSearchFunc()"></image>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<view class="loading_css" v-if="isShow">
				<u-loading size="36" color="#E60012"></u-loading>
				<view>加载中</view>
			</view>
			<!---flex布局flex布局开始-->
			<view class="flex benben-flex-layout flex-wrap align-center recommendCommodityList_flex_1" v-else>
				<view class='flex flex-wrap align-center recommendCommodityList_fd1_0' v-for="(item, index) in list" :key="index" @tap.stop="handleJumpDiy" data-type="navigateTo" :data-url="`/pages/homePage/courseDetail/courseDetail?id=${item.aid}`">
					<view class='flex flex-wrap align-center'>
						<image class='recommendCommodityList_fd1_0_c0_c0' mode="aspectFill" :src='item.thumb'>
						</image>
					</view>
					<view class='flex flex-wrap align-center flex-sub recommendCommodityList_fd1_0_c1'>
						<view class='flex flex-wrap align-center flex-sub'>
							<text class='recommendCommodityList_fd1_0_c1_c0_c0'>{{item.title}}</text>
							<view class='flex flex-wrap align-center flex-sub recommendCommodityList_fd1_0_c1_c0_c1'>
								<text class='recommendCommodityList_fd1_0_c1_c0_c1_c0'>讲师名称：{{item.lecturer}}</text>
								<view class='flex  recommendCommodityList_fd1_0_c1_c0_c1_c1'></view>
								<text class='recommendCommodityList_fd1_0_c1_c0_c1_c0'>{{item.course_hour}}课时</text>
							</view>
						</view>
					</view>
				</view>
				<view class="loadmore" v-if="last_page > 1">
					<u-loadmore font-size="24" :status="status" :icon-type="iconType" :load-text="loadText" />
				</view>
			</view>

			<!---flex布局flex布局结束-->
			
			<view class="noData" v-if="list.length == 0 && !isShow">
				<image :src='STATIC_URL+"no.png"'></image>
			</view>

		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},

		data() {
			return {
				"keyword": "",
				"cid": "",
				"list": [],
				"page": 1,
				"is_pull": true,
				"last_page": 1,
				"status": 'loadmore',
				"iconType": 'flower',
				"loadText": {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '我也是有底线的'
				},
				"isShow": true,
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {
			keyword() {
				if (!this.keyword) {
					this.page = 1;
					this.is_pull = true;
					this.isShow = true;
					this.getList();
				}
			}
		},
		onLoad(options) {
			let {
				keyword,
				cid
			} = options
			if (keyword !== undefined) this.keyword = keyword;
			if (cid !== undefined) this.cid = cid;
			this.getList();
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		// 下拉刷新
		onPullDownRefresh() {
			this.page = 1;
			this.is_pull = true;
			this.isShow = true;
			this.getList();
		},
		// 上拉加载
		onReachBottom() {
			if (this.page >= this.last_page) return;
			this.status = 'loading';
			this.page++;
			setTimeout(() => {
		
				if (this.page >= this.last_page) this.status = 'nomore';
				else this.status = 'loading';
				this.is_pull = false;
				this.getList();
			}, 500)
		},
		onPageScroll(e) {

		},
		methods: {
			//清除搜索框
			clearSearchFunc() {
				this.keyword = '';
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getList();
			},
			searchFunc() {
				this.page = 1;
				this.is_pull = true;
				this.isShow = true;
				this.getList();
			},
			// 获取课程列表  post65dd81e6f0119
			getList() {
				this.$api.post(global.apiUrls.post65dd81e6f0119, {
					page: this.page,
					keyword: this.keyword
				}).then(res => {
					// console.log(res);
					uni.stopPullDownRefresh();
					this.isShow = false;
					if (res.data.code == 1) {
						this.last_page = res.data.data.last_page;
						if (this.is_pull) {
							this.list = res.data.data.data;
						} else {
							this.list = this.list.concat(res.data.data.data);
						}
					} else {
						this.$message.info(res.data.msg);
					}
				})
			},
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: url(image-path('137.png')) no-repeat;
		background-size: 100% auto;
	}

	.recommendCommodityList_flex_0 {
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
	}

	.recommendCommodityList_fd0_0_c1_c2 {
		width: 36rpx;
		height: 36rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.recommendCommodityList_fd0_0_c1_c1 {
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		margin: 0 0 0 16rpx;
		transform: translateY(3rpx);
	}

	.recommendCommodityList_fd0_0_c1_c0 {
		width: 48rpx;
		height: 48rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.recommendCommodityList_fd0_0_c1 {
		background: #F9F9F9;
		height: 64rpx;
		border-radius: 34rpx 34rpx 34rpx 34rpx;
		padding: 0rpx 24rpx 0rpx 24rpx;
		margin: 0rpx 0rpx 0rpx 24rpx;
		width: 574rpx;
	}

	.recommendCommodityList_fd0_0_c0_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
	}

	.recommendCommodityList_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
		margin-top: 16rpx;
		line-height: 88rpx;
	}

	.recommendCommodityList_flex_1 {
		padding: 0rpx 36rpx 0rpx 36rpx;
	}

	.recommendCommodityList_fd1_0_c1_c0_c1_c1 {
		background: #999;
		width: 1rpx;
		height: 27rpx;
		margin: 0rpx 20rpx 0rpx 20rpx;
		transform: scaleX(0.5);
	}

	.recommendCommodityList_fd1_0_c1_c0_c1_c0 {
		font-size: 24rpx;
		color: rgba(153, 153, 153, 1);
	}

	.recommendCommodityList_fd1_0_c1_c0_c1 {
		margin: 18rpx 0rpx 0rpx 0rpx;
	}

	.recommendCommodityList_fd1_0_c1_c0_c0 {
		font-size: 28rpx;
		font-weight: 400;
		-webkit-line-clamp: 2;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.recommendCommodityList_fd1_0_c1 {
		margin: 0rpx 0rpx 0rpx 32rpx;
	}

	.recommendCommodityList_fd1_0_c0_c0 {
		width: 250rpx;
		height: 168rpx;
		border-radius: 16rpx;
	}

	.recommendCommodityList_fd1_0 {
		background: #fff;
		width: 100%;
		background-size: 100% auto;
		border-radius: 16rpx;
		margin: 24rpx 0rpx 0rpx 0rpx;
		padding: 28rpx 32rpx 28rpx 32rpx;
	}
</style>